import 'package:find_friend/const/const.dart';
import 'package:find_friend/pages/guide/guidePage.dart';
import 'package:flutter/material.dart';
import 'package:page_transition/page_transition.dart';


class ScaleLaunch extends StatefulWidget {
  @override
  _ScaleLaunchState createState() => _ScaleLaunchState();
}

class _ScaleLaunchState extends State<ScaleLaunch> with SingleTickerProviderStateMixin{

  Animation<double> _animation;
  AnimationController _animationController;
  bool isoffstage = false;

  @override
  void initState() {
    super.initState();

    _animationController = AnimationController(vsync: this, duration: const Duration(seconds: 2));
    CurvedAnimation _curve = CurvedAnimation(curve: Curves.easeIn, parent: _animationController);
    _animation = Tween<double>(begin: 1.0, end: 1.8).animate(_curve);

    _animationController.addListener(() { 
      if(_animationController.isCompleted){
        setState(() {
          isoffstage = true;
        });

        // Future.delayed(const Duration(milliseconds: 100)).then((value){
        //   Navigator.push(context, PageTransition(
        //     child: GuideScreen(),
        //     type: PageTransitionType.fade
        //   ));
        // });
      }

      setState(() {
      });
    });

    Future.delayed(const Duration(microseconds: 100)).then((value) => _animationController.forward());
  }

  @override
  Widget build(BuildContext context) {
    return Offstage(
      offstage: isoffstage,
      child: Container(
        color: APP_main_color,
        child: ScaleTransition(
          scale: _animation,
          child: Opacity(
            opacity: 2 - _animation.value,
            child: Image.asset("assets/launch.jpg")
          )
        ),
      ),
    );
  }
}